import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.security.InvalidParameterException;
import java.util.Scanner;


public class FileWork {

	static Scanner sc = new Scanner(System.in);
	
	static String [] readFile (String fileName1) throws Exception {
		if (fileName1 == null) {
			throw new InvalidParameterException("Invalid parameter!");
		}
		Reader fileReader = null;
		String [] words = null;
		File file1 = null;		
		file1 = new File("file1.txt");
		if (!file1.exists()) {
			throw new FileNotFoundException("File doesn't exist!");
		}
		if (!file1.canRead())
			throw new SecurityException("Cannnot read files!");
		
		try {			
			fileReader = new FileReader("file1.txt"); // nqma chetene na cql file
			char[]howMuchToRead = new char[20]; 
			fileReader.read(howMuchToRead);
			System.out.println(new String(howMuchToRead));
			words = howMuchToRead.toString().split(" ");
			return words;
			
		}catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				fileReader.close();
				return words;
			}catch (IOException e) {
				e.printStackTrace();
			}			
		} return words;			
	}
	
	//finds all words starting with a and adds them to a new String array
	static String [] findAllWordsWithA(String [] words) {
		if (words == null){
			throw new InvalidParameterException("Invalid parameter!");
		}
		String wordsWithA = "";
		for (int i = 0; i < words.length; i++) {
			if (words[i] != null && words[i].startsWith("a")) {
				wordsWithA = words[i] + " ";
			}
		}
		String [] wordsWithAArray = wordsWithA.split(" ");
		return wordsWithAArray;				
	}
	
	
	static void writeToNewFileChosenWords(String [] words) {
		if (words == null) {
			throw new InvalidParameterException("Invalid parameter!");
		}File file2 = null;		
		file2.createNewFile();
		
	}
	
	
	public static void main(String[] args) throws Exception {
		readFile("file1.txt");
	}

}
